$.ajaxSetup({cache:false});

function getRequest() {
	var url = location.search; // 获取url中"?"符后的字串
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
		}
	}
	return theRequest;
}

/* INIT */
$(document).ready(function() {
	accountSecurity.init();
});
var messageInfo = decodeURI(getRequest()['messageInfo']);
var accountSecurity = {
	init : function() {
		$('.leftnav li:eq(7)').addClass('active');
		if (messageInfo && messageInfo != 'undefined') {
			if (messageInfo == 1) {
				messageInfo = "邮箱绑定成功！";
			}
			if (messageInfo == 2) {
				messageInfo = "您已经成功绑定邮箱，无须重复操作！";
			}
			$('.message-info-text').text(messageInfo);
			$('.message-info').show();
		}
		$('.security-level li:eq(0)').removeClass('active');
		$('.security-level li:eq(1)').removeClass('active');
		$('.security-level li:eq(2)').removeClass('active');
		$('.security-btn-01:eq(0)').on('click', accountSecurity.bindPhoneNumClick);
		$('.security-btn-02:eq(0)').on('click', accountSecurity.editPhoneNumClick);
		$('.security-btn-01:eq(1)').on('click', accountSecurity.bindEmailClick);
		$('.security-btn-02:eq(1)').on('click', accountSecurity.editEmailClick);
		$('.infoClose').on('click', accountSecurity.closeInfo);

		$("#loading").show();

		$.ajax({
			url : getRootPath() + '/customerajax/securityCenter!queryAccountInfo.action',
			type : 'post',
			dataType : 'json',
			cache:false,
			success : function(res) {
				var level = 'low';
				var levelInfo = '低';
				switch (res.bindNum) {
				case 1:
					level = 'medium';
					levelInfo = '中';
					break;
				case 2:
					levelInfo = '高';
					level = 'high';
					break;
				}
				$('.security-level .level:eq(' + res.bindNum + ')').prevAll().addClass(level);
				$('.security-level .level:eq(' + res.bindNum + ')').addClass(level);
				$('.security-level .level_info').text(levelInfo);
				if (res.phoneNum) {
					$('.list-unstyled p:eq(1)').text("您的手机已验证: " + res.phoneNum);
					$('.security-btn-02:eq(2)').on('click', accountSecurity.editQuotaClick);
				} else {
					$('.security-btn-02:eq(2)').on('click', accountSecurity.bindPhoneNumClick);
				}
				if (res.emailAddress)
					$('.list-unstyled p:eq(3)').text("已绑定邮箱：  " + res.emailAddress);
				if (res.quota)
					$('.quota').text(res.quota.replace(/\.?0*$/,'') + " 元");

				$('.bindPhoneStatus').toggle(!res.phoneNum);
				$('.editPhoneStatus').toggle(!(!res.phoneNum));
				$('.bindEmailStatus').toggle(!res.emailAddress);
				$('.editEmailStatus').toggle(!(!res.emailAddress));

				// 显示
				$("#serList").show();
				$("#loading").hide();
			},
			error : function(e) {
			}
		});

		// $.get( getRootPath() +
		// '/customerajax/securityCenter!queryAccountInfo.action', function(res)
		// {
		// var level = 'low';
		// var levelInfo = '低';
		// switch (res.bindNum) {
		// case 1:
		// level = 'medium';
		// levelInfo = '中';
		// break;
		// case 2:
		// levelInfo = '高';
		// level = 'high';
		// break;
		// }
		// $('.security-level .level:eq(' + res.bindNum +
		// ')').prevAll().addClass(level);
		// $('.security-level .level:eq(' + res.bindNum + ')').addClass(level);
		// $('.security-level .level_info').text(levelInfo);
		// if(res.phoneNum) {
		// $('.list-unstyled p:eq(1)').text("您的手机已验证: " + res.phoneNum);
		// $('.security-btn-02:eq(2)').on('click',
		// accountSecurity.editQuotaClick);
		// } else {
		// $('.security-btn-02:eq(2)').on('click',
		// accountSecurity.bindPhoneNumClick);
		// }
		// if(res.emailAddress)
		// $('.list-unstyled p:eq(3)').text("已绑定邮箱： " + res.emailAddress);
		// if(res.quota)
		// $('.quota').text(res.quota + " 元");
		//		   
		// $('.bindPhoneStatus').toggle(!res.phoneNum);
		// $('.editPhoneStatus').toggle(!(!res.phoneNum));
		// $('.bindEmailStatus').toggle(!res.emailAddress);
		// $('.editEmailStatus').toggle(!(!res.emailAddress));
		//			
		// //显示
		// $("#serList").show();
		// $("#loading").hide();
		// });
	},
	closeInfo : function() {
		$('.message-info').hide();
	},
	bindPhoneNumClick : function() {
		window.location.href = getRootPath() + '/customer/securityCenter!load.action?name=bindPhone';
	},
	editPhoneNumClick : function() {
		window.location.href = getRootPath() + '/customer/securityCenter!load.action?name=checkPhoneStatus';
	},
	bindEmailClick : function() {
		window.location.href = getRootPath() + '/customer/securityCenter!load.action?name=bindEmail';
	},
	editEmailClick : function() {
		window.location.href = getRootPath() + '/customer/securityCenter!load.action?name=checkEmailStatus';
	},
	editQuotaClick : function() {
		window.location.href = getRootPath() + '/customer/securityCenter!load.action?name=editPayQuota';
	}
};